﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using DataProvider;

namespace SGBDSecurity
{
    public partial class ViewTable : Form
    {
        UserDataProvider aDataProvider;
        User aUser;

        public ViewTable(User iUser)
        {
            aDataProvider = new UserDataProvider();
            aUser = iUser;
            List<Table> aList = aDataProvider.GetUserViewTable(iUser);
            

            InitializeComponent();
            dataGridView1.DataSource = aList;
            this.lNome.Text = iUser.Login;
            this.lNivel.Text = iUser.Classe + "";
         

        }

        private void ViewTable_Load(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btnView_Click(object sender, EventArgs e)
        {
            if(dataGridView1.SelectedRows.Count > 0)
            {
                Table aTable = new Table();
                aTable.STable = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                aTable.STipoSeguranca = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                if (aTable.STipoSeguranca.Equals("tabela"))
                {
                    aTable.Classe = int.Parse(dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
                }
                ViewTable2 view = new ViewTable2(aUser, aTable);
                view.Visible = true;
            }   
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
